package com.cmas.platform.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.baomidou.mybatisplus.extension.toolkit.SqlHelper;
import com.cmas.platform.domain.Comment;
import com.cmas.platform.domain.Post;
import com.cmas.platform.domain.Region;
import org.springframework.stereotype.Service;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.aidex.common.core.domain.BaseEntity;
import com.aidex.common.utils.StringUtils;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.cmas.platform.mapper.ApproveRecordMapper;
import com.cmas.platform.domain.ApproveRecord;
import com.cmas.platform.service.ApproveRecordService;
import org.springframework.transaction.annotation.Transactional;

/**
 * 审核记录表Service业务层处理
 * @author su
 * @email 1218819874@qq.com
 * @date 2023-03-13
 */
@Service
public class ApproveRecordServiceImpl extends ServiceImpl<ApproveRecordMapper, ApproveRecord> implements ApproveRecordService {

    private static final Logger log = LoggerFactory.getLogger(ApproveRecordServiceImpl.class);


    /**
     * 查询审核记录表列表
     * @param approveRecord 审核记录表
     * @return 审核记录表
     */
    @Override
    public List<ApproveRecord> selectApproveRecordList(ApproveRecord approveRecord) {
        QueryWrapper<ApproveRecord> queryWrapper=setQueryWrapper(approveRecord);
        return baseMapper.selectList(queryWrapper);
    }
    /**
     * 设置QueryWrapper条件
     * @param
     * @return
     */
    private QueryWrapper<ApproveRecord> setQueryWrapper(ApproveRecord approveRecord){
        QueryWrapper<ApproveRecord> queryWrapper=new QueryWrapper<>();
        if(StringUtils.isNotEmpty(approveRecord.getItemTableName()))
        {
            queryWrapper.lambda().like(ApproveRecord::getItemTableName,approveRecord.getItemTableName());
        }
        if(StringUtils.isNotEmpty(approveRecord.getItemId()))
        {
            queryWrapper.lambda().eq(ApproveRecord::getItemId,approveRecord.getItemId());
        }
        if(StringUtils.isNotEmpty(approveRecord.getType()))
        {
            queryWrapper.lambda().eq(ApproveRecord::getType,approveRecord.getType());
        }
        if(StringUtils.isNotEmpty(approveRecord.getBeforeStatus()))
        {
            queryWrapper.lambda().eq(ApproveRecord::getBeforeStatus,approveRecord.getBeforeStatus());
        }
        if(StringUtils.isNotEmpty(approveRecord.getAfterStatus()))
        {
            queryWrapper.lambda().eq(ApproveRecord::getAfterStatus,approveRecord.getAfterStatus());
        }
        queryWrapper.lambda().orderByAsc(ApproveRecord::getItemTableName);
        queryWrapper.lambda().orderByDesc(ApproveRecord::getCreateTime);
        return queryWrapper;
    }

    /**
     * 批量删除审核记录表
     * @param ids 需要删除的审核记录表ID
     * @return 结果
     */
    @Transactional(readOnly = false)
    @Override
    public int deleteApproveRecordByIds(String[] ids) {
        return baseMapper.deleteApproveRecordByIds(ids, BaseEntity.DEL_FLAG_DELETE);
    }


}
